// 最长回文子串
class Solution {
    bool dp[1001][1001] = {false};
public:
    int getLongestPalindrome(string A) {
        int n = A.size();
        int ret = 0;
        for(int i = n  - 1; i >= 0; i--)
        {
            for(int j = i; j < n; j++)
            {
                if(A[i] == A[j])
                    dp[i][j] = i + 1 >= j ? true : dp[i + 1][j - 1];
                if(dp[i][j] && ret < j - i + 1)
                    ret = j - i + 1;
            }
        }
        return ret;
    }
};

// 买卖股票的最好时机(一)
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<int> prices(n);
    for(int i = 0; i < n; i++)
        cin >> prices[i];
    int ret = 0;
    int prevMin = prices[0];
    for(int i = 1; i < n; i++)
    {
        prevMin = min(prevMin, prices[i]);
        ret = max(ret, prices[i] - prevMin);
    }
    cout << ret << endl;
    return 0;
}

// 过河卒
#include <iostream>
using namespace std;
long long dp[1002][1002] = {0};

int main() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    x += 1, y += 1;
    dp[0][1] = 1;
    for(int i = 1; i <= n + 1; i++)
    {
        for(int j = 1; j <= m + 1; j++)
        {
            if((x != i && y != j && abs(i - x) + abs(j - y) == 3) || (x == i && y == j))
                dp[i][j] = 0;
            else
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        }
    }
    cout << dp[n + 1][m + 1] << endl;
    return 0;
}

// 游游的水果大礼包
#include <iostream>
using namespace std;

int main()
{
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    long long ret;
    for(long long x = 0; x <= min(n / 2, m); x++)
    {
        long long sum = x * a;
        sum += b * min(n - 2 * x, (m - x) / 2);
        ret = max(ret, sum);
    }
    cout << ret << endl;
    return 0;
}

// 买卖股票的最好时机(二)
#include <iostream>
using namespace std;

const int N = 1e5+10;

int main() {
    int n = 0;
    cin >> n;
    int arr[N];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    int ret = 0;
    for(int i = 1; i < n; i++)
        if(arr[i] > arr[i - 1])
            ret += arr[i] - arr[i - 1];
    cout << ret << endl;
    return 0;
}

// 倒置字符串
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<string> strs;
    string s;
    while(cin >> s)
        strs.push_back(s);
    string ret;
    auto it =strs.rbegin();
    while(it != strs. rend())
    {
        ret += *it + " ";
        it++;
    }
        
    ret.pop_back();
    cout << ret << endl;
    return 0;
}

// 删除公共字符
#include <iostream>
#include <string>
using namespace std;

int main() {
    bool hash[128] = {0};
    string s1, s2;
    getline(cin, s1);
    getline(cin, s2);
    for(char ch : s2)
        hash[ch] = true;
    string ret;
    for(char ch : s1)
        if(hash[ch]) continue;
        else ret += ch;
    cout << ret << endl;
    return 0;
}

// 两个链表的第一个公共结点
class Solution {
    public:
        ListNode* FindFirstCommonNode( ListNode* pHead1, ListNode* pHead2) {
            ListNode *cur1 = pHead1, *cur2 = pHead2;
            while(cur1 != cur2)
            {
                cur1 = cur1 != nullptr ? cur1->next : pHead2;
                cur2 = cur2 != nullptr ? cur2->next : pHead1;
            }
            return cur1;
        }
    };

// mari和shiny
#include <iostream>
#include <string>
using namespace std;

int main()
{
    string str;
    int n;
    cin >> n >> str;
    long long s = 0, h = 0, y = 0;
    for(char ch : str)
    {
        if(ch == 's')
            s++;
        else if(ch == 'h')
            h += s;
        else if(ch == 'y')
            y += h;
    }
    cout << y << endl;
    return 0;
}